package thread.single;

/**
 * 懒汉式单例 - 第一次调用getSingleTon方法才实例化对象
 */
public class LazySingleTon {
    private  static  volatile LazySingleTon singleTon;

    private LazySingleTon(){
        int x= 10;
        int y= 20;
        int z = 30;
    }
    // 第一次调用获取单例对象方法时才实例化对象
    public static LazySingleTon getSingleTon(){
        if (singleTon == null){
            synchronized (LazySingleTon.class){
                if (singleTon ==null){
                    singleTon = new LazySingleTon();
                }
            }
        }
        return singleTon;
    }
}
